package lch.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qiniu.util.Json;
import lch.dao.MemberDao;
import lch.pojo.Member;
import lch.service.MemberService;
import lch.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author lch
 * @date 2019-12-25 11:56
 */
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;


    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }

    @Override
    public void add(Member member) {
        String password = member.getPassword();
        //密码需要进行加密
        if (password != null) {
            password = MD5Utils.md5(password);
            member.setPassword(password);
        }
        memberDao.add(member);
    }

    @Override
    public List<Integer> findMemberCountByMonths(List<String> months) {
        List<Integer> count=new ArrayList<>();
        for (String month : months) {
            String date=month+".31";
            Integer memberCountBeforeDate = memberDao.findMemberCountBeforeDate(date);
            count.add(memberCountBeforeDate);
        }
        return count;
    }


}
